package com.hd.crdao.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;

import com.hd.crdao.R;
import com.hd.crdao.adapter.LoanCarTabAdapter;
import com.hd.crdao.config.Config;
import com.hd.crdao.fragment.LoanCarBaseFragment;
import com.hd.crdao.fragment.LoancarChangeFragment;
import com.hd.crdao.utils.SPUtils;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.view.ExpandHeadView;
import com.hd.crdao.view.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 *@author Programming
 *@date 2017/7/10 0010
 */
public class NewLoanCarActivity extends FragmentActivity {
    @BindView(R.id.locancar_head)
    ExpandHeadView mLocancarHead;
    @BindView(R.id.pagersligingtabstrip)
    PagerSlidingTabStrip mPagersligingtabstrip;
    @BindView(R.id.pager)
    ViewPager mPager;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    public DisplayMetrics mDisplayMetrics;
    public LoanCarTabAdapter mLoanCarTabAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newloancar);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mDisplayMetrics = getResources().getDisplayMetrics();
        mLocancarHead.getLeftArrowLL().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mLocancarHead.getHeadViewRightText().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(UIUtils.getContext(), LoanCarBillsActivity.class));
            }
        });

        if (SPUtils.getInt(Config.userType, Config.CARBUSINESS_ACCOUNT) == Config.CARBUSINESS_ACCOUNT) {  //如果为车商
            mFragments.add(0, new LoancarChangeFragment());
        } else {
            mFragments.add(0, setState("2"));       //子账户  与之前一致
        }
        mFragments.add(1, setState("1"));
        mFragments.add(2, setState("3"));


        mLoanCarTabAdapter = new LoanCarTabAdapter(getSupportFragmentManager(), mFragments);
        mPager.setAdapter(mLoanCarTabAdapter);
        mPagersligingtabstrip.setViewPager(mPager);

        setTabValue();


    }

    private LoanCarBaseFragment setState(String state) {
        LoanCarBaseFragment loanCarBaseFragment = new LoanCarBaseFragment();
        Bundle bundle = new Bundle();
        bundle.putString("state", state);
        loanCarBaseFragment.setArguments(bundle);
        return loanCarBaseFragment;
    }

    private void setTabValue() {
        // 设置Tab是自动填充满屏幕的
        mPagersligingtabstrip.setShouldExpand(true);
        // 设置Tab的分割线是透明的
        mPagersligingtabstrip.setDividerColor(Color.TRANSPARENT);
        // 设置Tab底部线的高度
        mPagersligingtabstrip.setUnderlineHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, mDisplayMetrics));
        // 设置Tab Indicator的高度
        mPagersligingtabstrip.setIndicatorHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 2, mDisplayMetrics));
        // 设置Tab标题文字的大小
        mPagersligingtabstrip.setTextSize((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_SP, 15, mDisplayMetrics));
        // 设置Tab标题默认的颜色*
        mPagersligingtabstrip.setTextColor(getResources().getColor(
                R.color.get_record_text_unselected_color));
        // 设置选中Tab标题的颜色
        mPagersligingtabstrip.setSelectedTextColor(getResources().getColor(
                R.color.get_record_text_selected_color));
        // 设置Tab底部线的颜色
        mPagersligingtabstrip.setUnderlineColor(getResources().getColor(
                R.color.get_record_line_unselected_color));
        // 设置Tab Indicator的颜色
        mPagersligingtabstrip.setIndicatorColor(getResources().getColor(
                R.color.get_record_line_selected_color));
        mPagersligingtabstrip.setAllCaps(true);
    }


    public void setNotice(Integer... notices) {

        mPagersligingtabstrip.setNotices(Arrays.asList(notices));
        mPagersligingtabstrip.notifyDataSetChanged();
    }



}
